﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using C.Unite;
using C.Entities;
using ChanExt;
using MySoft.Data;
using System.Text;
using LitJson;

namespace ArtLand.OA.Project.HR
{
    public partial class HR_EmpIF :CommonPageBase
    {
        List<OA_Department> mentList = TbsDbSession.Default.From<OA_Department>().ToList();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTree();
            }
        }

        private void BindTree()
        {
            List<OA_Department> items = mentList.FindAll(delegate(OA_Department tas) { return tas.TopID == 0; });// TbsDbSession.Default.From<GS_ArticleSort>().Where(GS_ArticleSort._.FatherID == 0).OrderBy(GS_ArticleSort._.ShowNo.Asc).ToList();
            foreach (OA_Department row in items)
            {
                TreeNode node = new TreeNode();
                node.Text = row.DepName;
                node.Target = "main";
                node.NavigateUrl = "HR_EmpList.aspx?did=" + row.DepID + "&dname=" + row.DepName;
                node.Expanded = true;
                treeMenu.Nodes.Add(node);
                ResolveSubTree(row.DepID, node);
            }
        }

        private void ResolveSubTree(int id, TreeNode treeNode)
        {
            List<OA_Department> items = mentList.FindAll(delegate(OA_Department tas) { return tas.TopID == id; }); //TbsDbSession.Default.From<GS_ArticleSort>().Where(GS_ArticleSort._.FatherID == id).OrderBy(GS_ArticleSort._.ShowNo.Asc).ToList();
            if (items.Count > 0)
            {
                foreach (OA_Department row in items)
                {
                    TreeNode node = new TreeNode();
                    node.Text = row.DepName;
                    node.Target = "main";
                    node.NavigateUrl = "HR_EmpList.aspx?did=" + row.DepID + "&dname=" + row.DepName;
                    node.Expanded = true;
                    treeNode.Nodes.Add(node);
                    ResolveSubTree(row.DepID, node);
                }
            }

        }
    }
}